import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
from scipy.stats import pearsonr
import os

# 解决中文显示问题
try:
    font_path = fm.findfont('SimHei')
    prop = fm.FontProperties(fname=font_path)
    plt.rcParams['font.family'] = prop.get_name()
except:
    plt.rcParams['font.family'] = 'Arial'

# 创建模拟数据 - 增加数据集间的差异
temperature = np.linspace(0.1, 1.0, 20)
entropy_rate = {
    'CIFAR-10': 0.8 - 0.7*temperature,
    'FEMNIST': 0.85 - 0.75*temperature,
    'UCI-Activity': 0.75 - 0.65*temperature
}

# 创建图表
fig, ax = plt.subplots(figsize=(7, 5))

# 设置线型和颜色
line_styles = {
    'CIFAR-10': {'color': '#1f77b4', 'linestyle': '-', 'linewidth': 2.5},
    'FEMNIST': {'color': '#ff7f0e', 'linestyle': '--', 'linewidth': 2.5},
    'UCI-Activity': {'color': '#2ca02c', 'linestyle': '-.', 'linewidth': 2.5}
}

# 绘制趋势线（不加markers）
for dataset in entropy_rate.keys():
    ax.plot(temperature, entropy_rate[dataset], 
            label=f'{dataset}',
            **line_styles[dataset])

# 添加关键点标注
# ax.text(0.4, entropy_rate['FEMNIST'][7]-0.02, "FEMNIST: r=-0.89", 
#         fontsize=12, color='#ff7f0e')
# ax.text(0.6, entropy_rate['UCI-Activity'][11]-0.02, "UCI-Activity: r=-0.83", 
#         fontsize=12, color='#2ca02c')

# 设置坐标轴
ax.set_xlabel('Temperature Coefficient', fontsize=14)
ax.set_ylabel('Entropy Variation Rate', fontsize=14)
# ax.set_title('不同数据集下的熵变率-温度演化趋势', fontsize=16, pad=15)

# 添加图例
ax.legend(loc='upper right', frameon=True)

# 添加网格
ax.grid(True, linestyle='--', alpha=0.7)

# 设置坐标轴范围
ax.set_xlim(0.05, 1.05)
ax.set_ylim(0.05, 0.95)

# 添加参考线
ax.axhline(y=0.7, color='r', linestyle='-', alpha=0.3)
ax.text(1.02, 0.69, 'Stability Threshold', color='r', fontsize=12, ha='right')

# 调整布局
plt.tight_layout()

# 保存为文件
output_path = 'entropy_temperature_lines.png'
plt.savefig(output_path, dpi=300, bbox_inches='tight')
plt.show()
